//
//  SEProtocolAPI.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/5/26.
//

import Moya

enum SECommonAPI {
    case protocolDetail(type: Int)
    case appVersion(flag: Int = 2)
    case appVersionFromAppStore
}

extension SECommonAPI: TargetType {
    var baseURL: URL {
        switch self {
        case .appVersionFromAppStore:
            return URL(string: SEApiManager.appStoreUrl)!
        default:
            return URL(string: SEApiManager.baseUrl)!
        }
    }

    var path: String {
        switch self {
        case .protocolDetail:
            return "/smarteye/smarteye-base/protocol/protocolDetail"
        case .appVersion:
            return "/smarteye/smarteye-manage/versionManagement/detailByFlag"
        case .appVersionFromAppStore:
            return "/lookup"
        }
    }

    var method: Moya.Method {
        switch self {
        case .appVersionFromAppStore:
            return .post
        default:
            return .get
        }
    }

    var sampleData: Data {
        return "".data(using: .utf8)!
    }

    var task: Task {
        return .requestParameters(parameters: parameters, encoding: URLEncoding.default)
    }

    var headers: [String : String]? {
        return SEApiManager.headers
    }

    private var parameters: [String: Any] {
        switch self {
        case let .protocolDetail(type):
            return ["type": type]
        case let .appVersion(flag):
            return ["flag": flag]
        case .appVersionFromAppStore:
            return ["id": "1569548072"]
        }
    }
    
}
